<!--
 * @Author: zhw
 * @Date: 2025-08-05 01:29:50
 * @LastEditTime: 2025-08-09 23:48:48
 * @LastEditors: zhw 443844039@qq.com
 * @Description: 教学规划
-->
<template>
  <div class="pageList">
    <TheTable
      ref="TheTableRef"
      :tableApi="coursePlanListApi"
      :searchList="searchList"
			:listColumns="listColumns"
			:actionArr="actionArr"
			:btnList="btnList"
      :needImport="true"
      exportUrl='/jsjx/coursePlan/export'
      exportName="教学规划"
			@handleClick="handleClick"
    />
    <TheImport ref="TheImportRef" :importApi="coursePlanImportDataApi" templateUrl='http://220.154.128.89:9443/statics/2025/09/17/课程计划_20250917141635A014.xlsx' @uploadSuccess="setTableList()"/>
  </div>
</template>
<script>
import TheTable from '@/componentsView/TheTable.vue';
import TheImport from '@/componentsView/TheImport.vue';
import { useDict } from '@/utils/dict/useDict'
import { searchList, listColumns, actionArr, btnList} from './data'
import { coursePlanListApi, coursePlanDelApi, coursePlanEditApi, coursePlanImportDataApi } from '@/api/teachingIdea/teachingPlan'
export default {
  name: 'TeachingPlan',
  components: { TheTable, TheImport },
  data() {
    return {
      coursePlanListApi,
      coursePlanImportDataApi,
      coursePlanDelApi,
      searchList,
      listColumns,
      actionArr,
      btnList,
      course_status: useDict('course_status'),
    }
  },

  methods: {
    setTableList(){
      this.$refs.TheTableRef.resetQuery()
    },
    handleClick({record,action}){
      let path = '';
      switch(action) {
        case 'add':
          path = '/teachingIdea/teachingPlan/detail?action='+action;
          this.$router.push(path);
          break;
        case 'look':
        case 'edit':
          path = '/teachingIdea/teachingPlan/detail?planId=' + record.planId + '&action='+ action;
          this.$router.push(path);
          break;
        case 'del':
          this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.teachingPlanDelFun(record.planId);
          }).catch(() => {
            this.$message.info('已取消删除');
          });
          break;
        case 'process':
          this.$confirm('此操作将更改项目状态, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.processFun(record)
          }).catch(() => {
            this.$message.info('已取消办理');
          });
          break
        case 'import':
          this.$refs.TheImportRef.open();
          break;
        default:
          break;
      }
    },
    processFun(row) {
      const currentStatus = row.courseStatus;
      const nextStatusIndex = this.course_status.findIndex(item => item.dictCode === currentStatus) + 1;
      const status = this.course_status[nextStatusIndex].dictCode;
      coursePlanEditApi({ planId:row.planId,courseStatus: status }).then(res => {
        if (res.code === 200) {
          this.$message.success(res.msg);
          this.setTableList()
        } else {
          this.$message.error(res.msg || '操作失败');
        }
      })
      .catch(error => {
        this.$message.error('请求失败: ' + error.message);
      });
    },
    teachingPlanDelFun(planId) {
      coursePlanDelApi(planId).then(res=>{
        if (res.code === 200) {
          this.$message.success(res.msg)
          this.setTableList()
        } else {
          this.$message.error(res.msg)
        }
      })
    }
  },
}
</script>
